# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=('apr-util' 'apr-util-devel')
pkgver=1.6.1
pkgrel=1
pkgdesc="The Apache Portable Runtime"
arch=('i686' 'x86_64')
url="https://apr.apache.org/"
makedepends=('apr-devel' 'libexpat-devel' 'libsqlite-devel')
options=('!libtool')
license=('APACHE')
source=("https://archive.apache.org/dist/apr/apr-util-${pkgver}.tar.bz2"
        apr-util-1.5.3-msys2.patch
        plugins.patch)
sha256sums=('d3e12f7b6ad12687572a3a39475545a072608f4ba03a6ce8a3778f607dd0035b'
            '55e5f524a5323476f5e224ed9d748a5417a64d5b21b89b2267a22ea4e32b9269'
            'd79c9202ce6ddc9a67a671ec5bcf495672330a4fa7e29446fa54db793f3f09fe')

prepare() {
  cd "${srcdir}/apr-util-${pkgver}"

  patch -p1 -i ${srcdir}/plugins.patch
  patch -p1 -i ${srcdir}/apr-util-1.5.3-msys2.patch

  autoreconf -fi
}

build() {
  cd "${srcdir}/apr-util-${pkgver}"
  ./configure --build=${CHOST} \
    --prefix=/usr \
    --with-apr=/usr \
    --with-expat=/usr \
    --without-gdbm \
    --without-ldap \
    --without-pgsql \
    --with-sqlite3=/usr

  make -j1
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd "${srcdir}/apr-util-${pkgver}"
  make -j1 check
}

package_apr-util() {
  depends=('apr' 'expat' 'libsqlite')
  groups=('libraries')

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
}

package_apr-util-devel() {
  pkgdesc="Libapr-util headers and libraries"
  groups=('development')
  depends=("apr-util=${pkgver}" "apr-devel" "libexpat-devel" "libsqlite-devel")
  options=('staticlibs')

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*-config ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
